﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HCFramework.Page.User.Login
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LabelMessage.Text = "";
        }
        protected void ButtonLogin_Click(object sender, EventArgs e)
        {
            // check login
            if (!C.UserController.IsMatch(TextBoxUsername.Text, C.UserController.EncryptPassword(TextBoxPassword.Text)))
            {
                LabelMessage.Text = "Username or password is not valid!";
                return;
            }

            // login
            C.UserController.Login(TextBoxUsername.Text, C.UserController.EncryptPassword(TextBoxPassword.Text));

            // return to previous page
            string returnURL = Request["returnURL"];
            if (String.IsNullOrEmpty(returnURL)) returnURL = "~/Default.aspx";
            Response.Redirect(returnURL);
        }

        protected void LinkButtonRegister_Click(object sender, EventArgs e)
        {
            string continueUrl = HttpUtility.UrlEncode(this.Request.Url.AbsoluteUri);
            if (!String.IsNullOrEmpty(Request["returnURL"])) continueUrl = HttpUtility.UrlEncode(Request["returnURL"]);
            Response.Redirect("~/User/Register/Register.aspx?returnURL=" + continueUrl);
        }

    }
}